

#ifndef OBJECTOVERVIEWTREEMODEL_H
#define OBJECTOVERVIEWTREEMODEL_H

#include <QAbstractItemModel>
#include <materialmanager.h>
#include <gfx/imesh.h>
#include <gfx/material.h>
#include <scene/entitynode.h>
#include <scene/groupnode.h>
#include <scene/lodnode.h>
#include <scene/light.h>
#include <scene/geometry.h>
#include <scene/sector.h>

#include <QList>

class ObjectOverviewTreeModel : public QAbstractItemModel
{
  Q_OBJECT
public:
  struct Item
  {
    enum Type
    {
      Type_Root,
      Type_EntityNode,
      Type_GroupNode,
      Type_LODNode,
      Type_Geometry,
      Type_Light,
      Type_Mesh,
      Type_Material
    } type;

    ceNode*         Node;
    union
    {
      ceEntityNode*   entityNode;
      ceGroupNode*    groupNode;
      ceLODNode*      lodNode;
      ceGeometry*     geometry;
      ceLightObject*  light;
      iMesh*          mesh;
      Material*       material;
    };

    Item* Parent;
    QList<Item*>  Children;
    int IndexOf (Item* item) const;
  };
private:
  Item* _root;

  bool  _showCompositions;

  void Clear (Item* item = 0);
  void AddNode (Item* parent, ceNode* node);
  void AddGeometry (Item* parent, ceGeometry* geometry);
  void AddLight (Item* parent, ceLightObject* light);
  void AddMesh (Item* item, iMesh* mesh);
  void AddMaterial (Item* item, Material* material);

  Item* FindItem (Item* item, ceNode* node);
  Item* FindItem (Item* item, Item::Type type);


public:
  ObjectOverviewTreeModel();

  void SetShowComposition (bool showComposition);
  bool IsShowComposition () const;

  bool IsLODNode (const QModelIndex& index) const;
  ceLODNode* AsLODNode (const QModelIndex& index) const;

  Item* GetItem (ceNode* node);
  Item* GetGeometryItem (ceNode* node);
  Item* GetMaterialItem (ceNode* node);
  QModelIndex GetIndex (ceNode* node);

  void Build (ceSector* sector);

  virtual int columnCount (const QModelIndex& parent = QModelIndex()) const;
  virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
  virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const;
  virtual QModelIndex parent (const QModelIndex& index) const;
  virtual int rowCount (const QModelIndex& parent = QModelIndex()) const;
  virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;

};

#endif // OBJECTOVERVIEWTREEMODEL_H
